// pages/information/information.js
const db=wx.cloud.database().collection('login')
Page({
  /**
   * 页面的初始数据
   */
  data: {
    _id:'',
    nickname:'',
    tip:'',
    tip_content:'',
    head_src:'',
  }, 
  tip: function (str) {
    const that = this

    that.setData({
      tip_content: str,
      tip: true
    })
    setTimeout(function () {
      that.setData({
        tip: false
      })
    }, 1000)
  },
  formSubmit(e){
    
    const that=this
    if(!e.detail.value.nickname){
      that.tip('输入信息不为空！')
      return
    }
    wx.showModal({
      title: '提示',
      content: '确认保存吗？',
      success:function(res){
        if (res.confirm) {
          db.doc(that.data._id).update({
            data:{
              nickname:e.detail.value.nickname
            },
            success:function(res){
             
              that.setData({
                nickname:e.detail.value.nickname
              })
              that.tip('保存成功！')
            }
          })
        }else{

        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
    this.setData({
      head_src:options.head_src
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const that=this
    const user=wx.getStorageSync('user')
    db.where({
      stuno:user
    }).get({
      success:function(res){
        that.setData(res.data[0])
      }
    })
  },
})